package com.lucenten.collect.gnss.entity;

import cn.quevo.common.entity.DoEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.exception.CheckParamsException;
import cn.quevo.common.lang.RegularUtils;
import cn.quevo.common.lang.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.beetl.sql.core.annotatoin.Table;

/**
 * O文件实时统计信息 实体BEAN
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2019/04/28 22:22:41
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@ApiModel(value = "ObsErvation O文件实时统计信息")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "t_obs_ervation")
public class ObsErvation extends DoEntity {

    /** 站点名称 */
    @ApiModelProperty(value = "站点名称")
    private String stationName;
    /** X */
    @ApiModelProperty(value = "X")
    private Double x;
    /** Y */
    @ApiModelProperty(value = "Y")
    private Double y;
    /** Z */
    @ApiModelProperty(value = "Z")
    private Double z;
    /** 双频/单频 */
    @ApiModelProperty(value = "双频/单频")
    private String obsFlag;
    /** 文件开始时间 */
    @ApiModelProperty(value = "文件开始时间")
    private String beginFileTime;
    /** 时间间隔1(秒) */
    @ApiModelProperty(value = "时间间隔1(秒)")
    private Double interval1;
    /** 时间间隔2(秒) */
    @ApiModelProperty(value = "时间间隔2(秒)")
    private Double interval2;
    /** 是否完整 */
    @ApiModelProperty(value = "是否完整")
    private String fullYn;
    /** 是否正确 */
    @ApiModelProperty(value = "是否正确")
    private String trueYn;
    /** 是否 */
    @ApiModelProperty(value = "是否")
    private String yn;
    /** 文件名称 */
    @ApiModelProperty(value = "文件名称")
    private String fileName;
    /** 文件类型(GPS,北斗,伽利略) */
    @ApiModelProperty(value = "文件类型(GPS,北斗,伽利略)")
    private String gnssType;

    // 年份
    private String year;
    // 截止日期
    private String endFileTime;

    /**
    * 公共参数验证
    */
    protected void validate() {
        if(StringUtils.isBlank(this.getStationName())){
            throw new CheckParamsException(6001, "站点名称不能为空");
        }
        if(StringUtils.isBlank(this.getFullYn())){
            throw new CheckParamsException(6009, "是否完整不能为空");
        }
        if(StringUtils.isBlank(this.getTrueYn())){
            throw new CheckParamsException(6010, "是否正确不能为空");
        }
        if(StringUtils.isBlank(this.getYn())){
            throw new CheckParamsException(6011, "是否不能为空");
        }
        if(StringUtils.isBlank(this.getFileName())){
            throw new CheckParamsException(6012, "文件名称不能为空");
        }
        // (GPS,北斗,伽利略)
        if(StringUtils.isBlank(this.getGnssType())){
            throw new CheckParamsException(6013, "文件类型不能为空");
        }
    }

    /**
    * 新增参数验证
    */
    public void validateCreate() {
        this.validate();
    }

    /**
    * 修改参数验证
    */
    public void validateUpdate() {
        if (StringUtils.isBlank(this.getId())) {
            throw new CheckParamsException(ResultStatusEnum.RECORD_UNSELECTED);
        }
        this.validate();
    }

    public static ObsErvation getInstance(String stationName, String fileName, String beginFileTime, String gnssType) {
        ObsErvation obsErvation = new ObsErvation();
        obsErvation.setStationName(stationName);
        obsErvation.fileName = fileName;
        obsErvation.gnssType = gnssType;
        /*obsErvation.x = "";
        obsErvation.y = "";
        obsErvation.z = "";*/
        obsErvation.beginFileTime =beginFileTime;
        obsErvation.interval1 = 0.0;
        obsErvation.fullYn = "完整";
        obsErvation.trueYn = "错误";
        obsErvation.yn = "是";
        obsErvation.year = "";
        obsErvation.endFileTime = "";
        return obsErvation;
    }
}
